/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * @author Administrator
 * Date: 2010-7-7 上午10:38:53
 */
package com.ccxe.manage.service.impl;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ccxe.manage.dao.impl.MenuItemDaoImpl;

/**
 * <角色权限分配> 页面初始化 service
 * 
 * @author wangyx
 * 
 */
public class PermissionRequestService extends BaseRequestService {

	public PermissionRequestService(HttpServletRequest req,
			HttpServletResponse resp) {
		this.request = req;
		this.response = resp;
	}

	private List<Map<?, ?>> roleList;

	private RoleDaoService roleService = new RoleDaoService();

	private MenuItemDaoImpl menuDao = new MenuItemDaoImpl();

	@Override
	protected String buildJspUrl() {
		return "/jsp/permission/list.jsp";
	}

	@Override
	public void buildParameters() {
		initRoleList();
		initPermissionTree();
	}

	/**
	 * 生成权限树
	 */
	private void initPermissionTree() {
		try {

			Object role_id = (roleList.isEmpty() ? "-1" : roleList.get(0).get("ROLE_ID"));
			List<Map<?, ?>> treeList = menuDao.queryAllByRole(role_id);
			request.setAttribute("treeList", treeList);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 初始化角色列表
	 */
	private void initRoleList() {
		try {
			roleList = roleService.queryAll();
			request.setAttribute("roleList", roleList);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
